let phone: number | string = '010-123456'
console.log(phone);
//函数使用联合类型
const fn = (something: number | boolean): boolean => {
  return !!something
}
console.log(fn(3));
//交叉类型
interface Persons {
  name: string,
  age: number
}
interface Man {
  sex: string
}
const xiaojie = (jie: Persons & Man): void => {
  console.log(jie.name);
  console.log(jie.age);
  console.log(jie.sex);
}
xiaojie({ name: '周文杰', age: 14, sex: '男' })
//类型断言
//这样写是会报错的，因为接口B没有定义run这个属性
// interface A {
//   run: string
// }
// interface B {
//   build: string
// }
// const fn = (type: A | B): string => {
//   return type.run
// }
//正确写法
interface A {
  run: string
}
interface B {
  build: string
}
const fn1 = (type: A | B): string => {
  return (type as A).run
}
console.log(fn1({ run: '你好啊' }));
//使用any临时断言
// window.abc = 123

// console.log((window as any).abc = 123);

//as const
// const a = 124
// a = 234 // 无法修改
// let names = '张杰' as const
// names = '刘德华' //无法修改

let arr = [1, 3, 5, 7, 9] as const
const arr2 = [2, 4, 6]
// arr.unshift(4) // 此时断言字面量为【10，20】,数据无法做任何修改
arr2.unshift(3)// 通过，并没有修改指针
console.log(arr);
console.log(arr2);
//类型断言是不具有影响力的
function toBoolean(something: any): boolean {
  return something as boolean
}
console.log(toBoolean(1)); //返回值是1




